package com.dms.modules.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dms.modules.product.entity.Product;
import com.dms.modules.product.mapper.ProductMapper;
import com.dms.modules.product.service.ProductQueryService;
import org.springframework.stereotype.Service;

/**
 * 产品查询服务实现类
 */
@Service
public class ProductQueryServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductQueryService {

    @Override
    public Product getById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public IPage<Product> getShopProducts(Page<Product> page, Long shopId) {
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Product::getMerchantId, shopId);
        return page(page, wrapper);
    }

    @Override
    public boolean existsById(Long id) {
        return getById(id) != null;
    }

    @Override
    public long count(Wrapper<Product> queryWrapper) {
        return baseMapper.selectCount(queryWrapper);
    }
} 